<?php
	include(ROOTPATH .'include'. DS .'protect.php');
	include ROOTPATH .'include'. DS .'isMyQuery.php';

	//$jsoncallback	= $_GET['jsoncallback'];
	$userName 		= getQuery('userName');	
	$password 		= getQuery('password');
	$password		= password($password);

	
	
	$sql = 'SELECT * FROM `'.DB_PRE.'user` WHERE `userName` = "'. $userName .'" and `passWord` = "'. $password .'" ';
	$users = $dbs -> select($sql);
	$users = $users[0];
	if( 0 == count($users) )
		exit( '{"status":"error","msg":" '.lang_username.'/'.lang_password_error.'."}');
	
	//$array['loginTimes']	=	$users['loginTimes'] + 1 ;

	$array['randomPass'] 	= rand(1000000000,99999999999);
	$array['loginTimes'] 	= $users['loginTimes'] + 1;
	$id = $users['id'];
	$dbs -> update( DB_PRE .'user' ,$array ,  ' `id` = '. $id );
	$users = new users ;	
	$users = $users -> getUser($id);
	initUserLogin($users);
	$user = new users();
	
	
	$referer 		= $_POST['referer'] ;
	$referer		= urldecode($referer);
	
	$refererArray	= parse_url($referer);
	$refererDefault = urlRewrite('option=home&id='. $user -> id());
	if( $refererArray['host'] != HOST_NAME || $refererArray['host'] == '' )
		$refererTo = $refererDefault;
	else
		$refererTo = $referer;
	
	
	echo '{"status":"ok","msg":"'.lang_login_success.'","url":'.json_encode($refererTo).'}' ;

?>